package com.knowif.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.knowif.dao.SchoolMapper;
import com.knowif.pojo.School;
import com.knowif.pojo.SchoolExample;

/**
 * @author ：Xh
 * @date ：Created in 2019/5/4 0004 21:28
 */
@Service
public class School_service {

    @Autowired
    private SchoolMapper schoolMapper;

    /**
     * School条件查询
     * @param schoolExample
     * @return
     */
    public List<School> selectSchool(SchoolExample schoolExample){
        return schoolMapper.selectByExample(schoolExample);
    }

    /**
     * 插入school
     * @param school
     * @return
     */
    public int saveSchool(School school){
        return schoolMapper.insert(school);
    }

    /**
     * 更新不为空的school属性
     * @param school
     * @return
     */
    public int updateSchoolNotNull(School school){
        return schoolMapper.updateByPrimaryKeySelective(school);
    }

    /**
     * 更新所有school属性
     * @param school
     * @return
     */
    public int updateSchool(School school){
        return schoolMapper.updateByPrimaryKey(school);
    }

    /**
     * 删除school
     * @param schoolId
     */
    public int deleteSchool(int schoolId){
        return schoolMapper.deleteByPrimaryKey(schoolId);
    }
    
    public School selectSchoolByEduInfo(Integer schoolId){
		SchoolExample schoolExample = new SchoolExample();
		if(schoolId == null){
			return new School();
		}
		schoolExample.createCriteria().andSchoolIdEqualTo(schoolId);
		List<School> schools = schoolMapper.selectByExample(schoolExample);
		if(schools == null || schools.isEmpty()){
			return new School();
		}else{
			return schools.get(0);
		}
	}
    
    
    public List<School> selectSchoolBySchoolIds(List<Integer> schoolIds){
    	if(schoolIds == null || schoolIds.isEmpty()){
    		return new ArrayList<School>();
    	}
    	SchoolExample schoolExample = new SchoolExample();
    	schoolExample.createCriteria().andSchoolIdIn(schoolIds);
    	List<School> schools = schoolMapper.selectByExample(schoolExample);
    	if(schools == null || schools.isEmpty()){
    		return new ArrayList<School>();
    	}else{
    		return schools;
    	}
    }

    /**
     * 返回schoolid
     * @return
     */
    public int selectMaxSchoolId(){
        return schoolMapper.selectMaxSchoolId();
    }
    
}








